package com.caterina.springBoard;
import java.awt.Container;
import java.util.ArrayList;
import java.util.Collection;
import javax.swing.BoxLayout;

import com.caterina.activities.BudgetActivity;
import com.caterina.activities.EmployeeContractsActivity;
import com.caterina.activities.EventContractsActivity;
import com.caterina.activities.RegistrationActivity;
import com.caterina.activities.ServicesActivity;
import com.caterina.activities.RegistrationActivity.RegistrationType;
import com.caterina.activities.RequestsActivity;
import com.caterina.activities.TransactionConfirmationActivity;
import com.caterina.activities.TransactionStatsActivity;
import com.caterina.activities.TransactionsActivity;
import com.caterina.activityManager.CActivity;
import com.caterina.components.CLabel;
import com.caterina.components.CPanel;
import com.caterina.components.COptionPane.MessageType;

import controllers.Permission;
import controllers.PermissionList;

public class Configuration {
	public static Collection<Category>getConfig(){
		if(configuration != null) return configuration;
		else configure();
		return configuration;
	}
	public static CPanel getSpringPanel(CActivity caller,PermissionList permissions,Container parent){
		getConfig();
		CPanel retPanel=new CPanel();
		retPanel.setLayout(new BoxLayout(retPanel, BoxLayout.X_AXIS));
		retPanel.add(new CPanel());
		configure();
		for(Category cat:configuration){
			if(cat.canView(permissions)){
				retPanel.add(cat.getCategoryPanel(caller, permissions));
				cat.setParent(parent);
				retPanel.add(new CLabel("  "));
			}
		}
		retPanel.add(new CPanel());
		return retPanel;
	}
	private static void configure(){
		//creazione dei pulsanti per la categoria evento
		configuration=new ArrayList<Category>();
		
		//Aggiunta categoria EVENTI
		configuration.add(new Category("SBBUTTON_EVENTS","icnEvents",
		//Link richieste
		new Link("SBBUTTON_REQUESTS", new RequestsActivity(null), 
				Permission.REQUESTS_VIEW,Permission.REQUESTS_CREATE,Permission.REQUESTS_MANAGE,
				Permission.REQUESTS_CREATE_ALL,Permission.REQUESTS_VIEW_ALL),
		//Link Preventivi
		new Link("SBBUTTON_BUDGET", new BudgetActivity(null), 
				Permission.BUDGETS_MANAGE,Permission.BUDGETS_MANAGE_ALL,Permission.BUDGETS_MODIFY,
				Permission.BUDGETS_VIEW,Permission.BUDGETS_VIEW_ALL),
		//Link Contratti
		new Link("SBBUTTON_CONTRACTS", new EventContractsActivity(null), 
				Permission.CONTRACTS_MANAGE,Permission.CONTRACTS_MANAGE_ALL,Permission.CONTRACTS_MODIFY,
				Permission.CONTRACTS_VIEW,Permission.CONTRACTS_VIEW_ALL),
		//Link Servizi
		new Link("SBBUTTON_SERVICES", new ServicesActivity(null), 
				Permission.SERVICE_MANAGE,Permission.SERVICE_VIEW),
		//Link assegna dipendenti ad evento
		new Link("SBBUTTON_EMPLOYEE_ADD_AT_EVENT",
				Permission.EMPLOYEES_MANAGE),
		//Link assegna risorse all'evento
		new Link("SBBUTTON_WAREHOUSE_EVENT_MANAGEMENT", 
				Permission.WAREHOUSE_RESOURCE_EVENTS_MANAGE)
		));
		
		//Aggiunta categoria DIPENDENTI
		configuration.add(new Category("SBBUTTON_EMPLOYEES","icnDipendenti",
		//Pulsante Dipendenti assunti
		new Link("SBBUTTON_EMPLOYEES", new EmployeeContractsActivity(null), 
				Permission.EMPLOYEES_MANAGE,Permission.EMPLOYEES_VIEW),
		//Pulsante Inserisci dipendenti
		new Link("SBBUTTON_EMPLOYEE_REGISTER", new RegistrationActivity(RegistrationType.EMPLOYEE,null), 
				Permission.EMPLOYEES_MANAGE),
		//Pulsante paga stipendi
		new Link("SBBUTTON_EMPLOYEES_PAY_WAGES", new AbstractOptionPane(MessageType.ACTIVITY,new TransactionConfirmationActivity(null)), 
				Permission.TRANSACTION_MANAGE)
		));
		
		//Aggiunta categoria CONTABILITA'
		configuration.add(new Category("SBBUTTON_ACCOUNTING","icnContabilita",
		//Pulsante Dipendenti assunti
		new Link("SBBUTTON_TRANSACTIONS",new TransactionsActivity(null), 
			Permission.TRANSACTION_MANAGE),
		//Pulsante Inserisci dipendenti
		new Link("SBBUTTON_ACCOUNTING_STATS", new TransactionStatsActivity(null),
			Permission.TRANSACTION_MANAGE)
		));
		
		//Aggiunta categoria Magazzino'
		configuration.add(new Category("SBBUTTON_WAREHOUSE","icnMagazzino",
		//Pulsante Dipendenti assunti
		new Link("SBBUTTON_WAREHOUSE_MANAGEMENT", 
			Permission.WAREHOUSE_MANAGE),
		//Link assegna risorse all'evento
		new Link("SBBUTTON_WAREHOUSE_EVENT_MANAGEMENT", 
			Permission.WAREHOUSE_RESOURCE_EVENTS_MANAGE)
		));
		
	}
	private static ArrayList<Category> configuration;
}
